package com.kiku.reggie.common;

import com.alibaba.fastjson.JSONObject;
import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
import org.apache.commons.lang.StringUtils;
import org.junit.Test;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;


/**
 * 短信发送工具类
 */
public class SMSUtils {
	public static void sendMessage(String phone,String code){
		DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou",
				"LTAI5t9iYCFQ6nSHAE5t823W", "WUpRDQKnigvYxQKj0xdbwB3UFtYmwv");
		IAcsClient client = new DefaultAcsClient(profile);

		CommonRequest request = new CommonRequest();
		request.setMethod(MethodType.POST);
		request.setDomain("dysmsapi.aliyuncs.com");
		request.setVersion("2017-05-25");
		request.setAction("SendSms");
		request.putQueryParameter("PhoneNumbers",phone);
		request.putQueryParameter("SignName", "kiku");
		request.putQueryParameter("TemplateCode", "SMS_463688491");

		/*code为生成的验证码*/

		Map<String,Object> map = new HashMap<>();
		map.put("code",code);
		request.putQueryParameter("TemplateParam", JSONObject.toJSONString(map));

		try {
			CommonResponse response = client.getCommonResponse(request);
			System.out.println(response.getData());
		} catch (ServerException e) {
			e.printStackTrace();
		} catch (ClientException e) {
			e.printStackTrace();
		}

	}

}
